﻿using System.Text.Json.Serialization;
using Microsoft.AspNetCore.Http;
using Simple.Common.Extensions;
using Simple.Repository.Models.ClassRoom;

namespace Simple.Services;

public class ClassDynamicOutputModel : ModelBase
{
    /// <summary>
    /// 主键Id
    /// </summary>
    public Guid? Id { get; set; } = null;

    /// <summary>
    /// 动态内容
    /// </summary>
    public string? Content { get; set; } = "";

    /// <summary>
    /// 发布人姓名
    /// </summary>
    public string CreateUserName { get; set; } = "";

    /// <summary>
    /// 发布人Id
    /// </summary>
    public Guid? CreatedUserId { get; set; } = null;

    /// <summary>
    /// 发布时间
    /// </summary>
    public DateTime? CreatedTime { get; set; } = null;

    /// <summary>
    /// 状态 0草稿，1发布,2屏蔽
    /// </summary>
    public int? State { get; set; } = null;

    /// <summary>
    /// 家长或老师标识
    /// </summary>
    public int? LoginType { get; set; }

    /// <summary>
    /// 关联幼儿Id
    /// </summary>
    public Guid? RelationshipChildrenId { get; set; }

    /// <summary>
    /// 幼儿姓名
    /// </summary>
    public string? RelationshipChildrenName { get; set; }

    /// <summary>
    /// 关系名称
    /// </summary>
    public string? RelationshipValue { get; set; }

    /// <summary>
    /// 发送班级
    /// </summary>
    public List<ClassDynamicSysClassesDto>? ClassList { get; set; } = null;

    /// <summary>
    /// 图片
    /// </summary>
    public List<ClassDynamicImage>? Images { get; set; } = null;

    /// <summary>
    /// 留言记录
    /// </summary>
    public List<ClassDynamicLeaveMessage>? LeaveMessages { get; set; } = null;

    public override void ConfigureMapper(Profile profile)
    {
        profile.CreateMap<ClassDynamic, ClassDynamicCreateOrUpdateModel>();

        profile.CreateMap<ClassDynamicCreateOrUpdateModel, ClassDynamic>();

        profile.CreateMap<ClassDynamic, ClassDynamicOutputModel>()
            .ForMember(p => p.RelationshipValue, options => options.MapFrom(p => p.Relationship.HasValue ? ((EnumParentRelationship)Enum.Parse(typeof(EnumParentRelationship), (p.Relationship ?? 0).ToString())).GetEnumDescription() : (p.LoginType == 1 || !p.LoginType.HasValue ? "老师" : string.Empty)));

        profile.CreateMap<ClassDynamicOutputModel, ClassDynamic>();
    }
}

/// <summary>
/// 班级权限Dto
/// </summary>
public class ClassDynamicSysClassesDto
{
    public string? ClassName { get; set; }

    public string? ClassId { get; set; }
}

public class ClassDynamicLeaveMessagesDto
{
    /// <summary>
    /// 留言内容
    /// </summary>
    public string? Content { get; set; }

    /// <summary>
    /// 班级动态Id
    /// </summary>
    public Guid? ClassDynamicId { get; set; }
}

public class MoveClassDynamicLeaveMessageOutputModel : ModelBase
{
    /// <summary>
    /// 主键Id
    /// </summary>
    public Guid? Id { get; set; } = null;

    /// <summary>
    /// 留言内容
    /// </summary>
    public string? LeaveMessageContent { get; set; }

    /// <summary>
    /// 留言时间
    /// </summary>
    public DateTime? LeaveMessageTime { get; set; }

    /// <summary>
    /// 留言人id
    /// </summary>
    public string? LeaveMessageUserId { get; set; }

    /// <summary>
    /// 留言人姓名
    /// </summary>
    public string? LeaveMessageUserName { get; set; }

    /// <summary>
    /// 班级动态Id
    /// </summary>
    public Guid? ClassDynamicId { get; set; }

    /// <summary>
    /// 所在班级id
    /// </summary>
    public Guid? ClassId { get; set; }

    /// <summary>
    /// 回复列表
    /// </summary>
    public List<LeaveMessageReply> Replys = new List<LeaveMessageReply>();

    /// <summary>
    /// 是否回复
    /// </summary>
    public bool IsReply { get; set; } = false;

    /// <summary>
    /// 是否发布
    /// </summary>
    public bool IsPublish { get; set; } = false;

    /// <summary>
    /// 家长或老师标识
    /// </summary>
    public int? LoginType { get; set; }

    /// <summary>
    /// 家属关系
    /// </summary>
    public string RelationshipValue { get; set; }

    /// <summary>
    /// 关联幼儿Id
    /// </summary>
    public Guid? RelationshipChildrenId { get; set; }

    /// <summary>
    /// 关联幼儿姓名
    /// </summary>
    public string RelationshipChildrenName { get; set; }

}

public class MoveClassDynamicOutputModel : ModelBase
{
    /// <summary>
    /// 主键Id
    /// </summary>
    public Guid? Id { get; set; } = null;

    /// <summary>
    /// 动态内容
    /// </summary>
    public string? Content { get; set; } = "";

    /// <summary>
    /// 发布人姓名
    /// </summary>
    public string CreateUserName { get; set; } = "";

    /// <summary>
    /// 发布人Id
    /// </summary>
    public Guid? CreatedUserId { get; set; } = null;

    /// <summary>
    /// 发布时间
    /// </summary>
    public DateTime? CreatedTime { get; set; } = null;

    /// <summary>
    /// 状态 0草稿，1发布,2屏蔽
    /// </summary>
    public int? State { get; set; } = null;

    /// <summary>
    /// 家长或老师标识
    /// </summary>
    public int? LoginType { get; set; }

    /// <summary>
    /// 关联幼儿Id
    /// </summary>
    public Guid? RelationshipChildrenId { get; set; }

    /// <summary>
    /// 幼儿姓名
    /// </summary>
    public string? RelationshipChildrenName { get; set; }

    /// <summary>
    /// 关系名称
    /// </summary>
    public string? RelationshipValue { get; set; }

    /// <summary>
    /// 发送班级
    /// </summary>
    public List<ClassDynamicSysClassesDto>? ClassList { get; set; } = null;

    /// <summary>
    /// 图片
    /// </summary>
    public List<ClassDynamicImage>? Images { get; set; } = null;

    /// <summary>
    /// 留言记录
    /// </summary>
    public List<MoveClassDynamicLeaveMessageOutputModel>? LeaveMessages { get; set; } = null;

    /// <summary>
    /// 点赞记录
    /// </summary>
    public List<DynamicLike>? DynamicLikes { get; set; } = null;

    /// <summary>
    /// 点赞人
    /// </summary>
    public List<string>? LikeUsers { get; set; } = null;

    /// <summary>
    /// 当前登录人是否点赞
    /// </summary>
    public bool IsLike { get; set; } = false;

    public override void ConfigureMapper(Profile profile)
    {
        profile.CreateMap<ClassDynamic, MoveClassDynamicOutputModel>()
            .ForMember(p => p.LikeUsers, options => options.MapFrom(o => o.DynamicLikes.Select(d => d.LikeParentName).ToList()))
            .ForMember(p => p.RelationshipValue, options => options.MapFrom(p => p.Relationship.HasValue ? ((EnumParentRelationship)Enum.Parse(typeof(EnumParentRelationship), (p.Relationship ?? 0).ToString())).GetEnumDescription() : (p.LoginType == 1 || !p.LoginType.HasValue ? "老师" : string.Empty)));

        profile.CreateMap<MoveClassDynamicOutputModel, ClassDynamic>();

        profile.CreateMap<ClassDynamicLeaveMessage, MoveClassDynamicLeaveMessageOutputModel>().ForMember(p => p.RelationshipValue, options => options.MapFrom(p => p.Relationship.HasValue ? ((EnumParentRelationship)Enum.Parse(typeof(EnumParentRelationship), (p.Relationship ?? 0).ToString())).GetEnumDescription() : (p.LoginType == 1 || !p.LoginType.HasValue ? "老师" : string.Empty)));
    }
}
